/*
 * @lc app=leetcode.cn id=283 lang=swift
 *
 * [283] 移动零
 */

// @lc code=start
//[0,1,0,3,12]
//遍历。是0将后面的
/**
 测试数据
 */
class Solution283 {
    // 采用双指针法
    func moveZeroes(_ nums: inout [Int]) {
        var left = 0
        for item in nums {
            if item != 0 {
                nums[left] = item
                left += 1
            }
        }
        for i in left..<nums.count {
            nums[i] = 0
        }
    }
    static func test() {
        var nums = [0,0,12,0,12]
        let solution = Solution283()
        solution.moveZeroes(&nums)
        print(nums)
    }
}
// @lc code=end

